package com.cdm.beans.cdm;

import java.util.List;

import net.sf.frails.JSFHelper;
import net.sf.frails.bean.annotations.DefMbean;
import net.sf.frails.bean.annotations.PreRender;
import net.sf.frails.bean.annotations.Prop;
import net.sf.frails.bean.annotations.SelectItems;

import com.cdm.domain.dao.ContentDAO;
import com.cdm.domain.dao.UserDAO;
import com.cdm.domain.service.Service;
import com.cdm.domain.service.ServiceImpl;
import com.cdm.persistence.Content;
import com.cdm.persistence.User;
import com.cdm.util.Constants;
import com.vivo.util.DTool;

@DefMbean
public class ContentHomeBean {

	@Prop
	User loginUser;

	@Prop
	List<Content> contents;

	@PreRender(failOutcome = "/content/contentHome")
	public boolean init() {
		Object object = JSFHelper.getFromApplication(Constants.LOGIN_USER_KEY);
		if (object instanceof User && object != null) {
			loginUser = (User) object;
		}
		if (loginUser != null && contents == null) {
			contents = contentDAO.findByProperty(ContentDAO.CPID, loginUser, 0);
		}

		DTool.d.debug("Enter CDM Home Page");
		return true;
	}

	private Service service = new ServiceImpl();
	private ContentDAO contentDAO = new ContentDAO();

}
